<?php

	class Loader {

		static function includeClass( $class ) {
			$filename = $class . '.php';
			$filename = str_replace( "_", "/", $filename );
			$file = INCLUDE_PATH . $filename;
			if( !file_exists( $file ) ) {
				@include_once $filename;
				if( !class_exists( $class ) && !interface_exists( $class ) ) {
					//throw new Exception( "Class $class was not found!" );
					@include_once( $class . '.php' );
				}
			} else {
				require_once $file;
			}
		}

		static function generateDbClass( $className ) {
			$table = camelToUnderScore( lcfirst( str_replace( ucfirst( MYSQL_PREFIX ) . 'Db_', '', $className ) ) );
			eval( 'class ' . $className . ' extends ' . 'AbstractDb {
						protected $_mainTable = \'' . MYSQL_PREFIX . $table . '\';
					}' );
		}

		static function generateSingularClass( $className ) {
			$last =explode( '_', $className );
			$last = array_pop( $last );
			eval( 'class ' . $className . ' extends ' . 'AbstractSingular {
						protected $_foreignKey = \'' . lcfirst( $last ) . 'Id\';
						protected $_dbClass = \'' . $last . '\';
					}' );
		}

		static function generatePluralClass( $className ) {
			$last =explode( '_', $className );
			$last = array_pop( $last );
			eval( 'class ' . $className . ' extends ' . 'AbstractPlural {
						protected $_dbClass = \'' . substr( $last, 0, -1 ) . '\';
					}' );
		}
	}